package com.lh.controller;



import com.lh.commonutils.Echarts;
import com.lh.commonutils.R;
import com.lh.entity.EduVideo;
import com.lh.feign.VodFeign;
import com.lh.service.IEduVideoService;
import io.swagger.annotations.ApiOperation;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 课程视频 前端控制器
 * </p>
 *
 * @author yms
 * @since 2021-06-05
 */
@RestController
@RequestMapping("/eduservice/edu-video")
//@CrossOrigin
public class EduVideoController {

    @Resource
    private IEduVideoService videoService;


    @ApiOperation(value = "添加小节")
    @PostMapping("addVideo")
    public R addVideo(@RequestBody EduVideo video){
        boolean b = videoService.save(video);
        if (b){
            return R.ok();
        }else {
            return R.error();
        }
    }

    @ApiOperation(value = "修改小节")
    @PostMapping("updateVideo")
    public R updateVideo(@RequestBody EduVideo video){
        boolean b = videoService.updateById(video);
        if (b){
            return R.ok();
        }else {
            return R.error();
        }
    }

    @ApiOperation(value = "删除小节")
    @DeleteMapping("{id}")
    public R deleteVideo(@PathVariable String id){
       R r= videoService.deleteVideo(id);
       return r;
    }

    @ApiOperation(value = "根据id查询小节")
    @GetMapping("getVideoInfo/{id}")
    public R getVideoInfo(@PathVariable String id){

        EduVideo video = videoService.getById(id);
        return R.ok().data("video",video);

    }

    @ApiOperation(value = "查询视频播放次数")
    @GetMapping("playout/{begin}/{end}")
    public R playout(@PathVariable String begin,
                        @PathVariable String end){
        List<Echarts> echarts=videoService.playout(begin,end);
        return R.ok().data("list",echarts);
    }

    @ApiOperation(value = "查询视频播放次数")
    @GetMapping("findPlayout")
    public R playout(){
        List<Echarts> echarts=videoService.findPlayout();
        return R.ok().data("list",echarts);
    }


    @ApiOperation(value = "根据视频凭证修改小节")
    @GetMapping("updateVideoInfo/{videoSourceId}")
    public void updateVideoInfo(@PathVariable String videoSourceId){
        videoService.updateVideoInfo(videoSourceId);
    }



}

